<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@include file="../base/base.jspf" %>
<link rel="stylesheet" type="text/css" href="${ctx}/static/css/style.css"/>
<div class="layui-form" style="padding: 47px 0 0 70px;">
    <input type="hidden" name="comId" value="${company.comId}"/>
    <div class="layui-col-xs6">
        <div class="layui-form-item">
            <label class="layui-form-label">公司名称</label>
            <div class="layui-input-inline">
                <input type="radio" value="1" name="comType" checked title="个人" lay-filter = "radio1" id="radio1"
                       <c:if test="${company.comType == '1' || company.comType == null}">checked</c:if>
                       class="layui-radio-disabled"/>
                <input type="radio" value="2" name="comType" title="企业" lay-filter = "radio2" id="radio2"
                       <c:if test="${company.comType == '2'}">checked</c:if>
                       class="layui-radio-disabled"/>
            </div>
        </div>
        <div class="layui-form-item" id="comName" <c:if test="${company.comType == '1' || company.comType == null}">hidden</c:if>>
            <label class="layui-form-label">公司名称</label>
            <div class="layui-input-inline">
                <input type="text" value="${company.comName}" name="comName"
                       placeholder="请输入公司名称"
                       class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">负责人</label>
            <div class="layui-input-inline">
                <input type="text" value="${company.comLinkman}" name="comLinkman" lay-verify="required"
                       placeholder="请输入负责人"
                       class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">负责人电话</label>
            <div class="layui-input-inline">
                <input type="text" value="${company.comMobile}" name="comMobile" lay-verify="required|phone"
                       placeholder="请输入负责人电话"
                       class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">地址</label>
            <div class="layui-input-inline">
                <input type="text" value="${company.comAddress}" name="comAddress"
                       placeholder="请输入地址"
                       class="layui-input"/>
            </div>
        </div>

        <%--<div class="layui-form-item">
            <label class="layui-form-label">协会图片</label>
            <div class="layui-col-xs6">
                <div class="text-center" id="clickToUploadHead">
                    <a href="javascript:void(0);" class="upimg-a">
                        <img style="height: 250px; width: 250px;" src="${ctx}${company.companyUrl}"
                             id="company-companySubmitPage-companyHead"
                             class="thumbnail"
                             onerror="javascript:this.src='${ctx}/static/images/pic-default.jpg';">
                        <div class="upimg-shade">
                    <span style="margin-left: 20%;">
                      点击上传
                    </span>
                        </div>
                    </a>
                </div>
            </div>
        </div>--%>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit id="company-front-submit" lay-filter="company-front-submit" value="确认"/>
    </div>
</div>

<script type="text/javascript">
    layui.config({
        base: "${ctx}/static/framework/layuiadmin/" //静态资源所在路径
    }).extend({
        index: "lib/index" //主入口模块
    }).use(["index", "form","upload","laydate"], function () {
        var upload = layui.upload, form = layui.form,laydate = layui.laydate;

        upload.render({
            elem: "#clickToUploadHead",
            url: "${ctx}/company/uploadFile",
            multiple: true,
            accept: "images",
            acceptMime: "image/*",
            size: 2048,//限制文件大小，单位 KB
            type: "post",
            done: function (result) {
                $("#company-companySubmitPage-companyHead").attr("src", "${ctx}" + result.path);

                $("input[name='companyUrl']").val(result.path);
            }
        });

        form.on("radio(radio2)",function(data){
            $("#comName").attr("style","display:block;");
        });
        form.on("radio(radio1)",function(data){
            $("#comName").attr("style","display:none;");
        });

        form.on("submit(company-front-submit)", function (data) {
            $("#company-front-submit").attr("disabled", true);
            tip_index = load();
            var field = data.field; //获取提交的字段
            $.ajax({
                async: true,
                url: "${ctx}/company/companySubmit",
                type: "post",
                dataType: "json",
                data: field,
                success: function (data) {
                    layer.close(tip_index);
                    if (data.result) {
                        parentTableReload("company-companyList-page");
                        successUp(data.info);
                        closeDialog();
                    } else {
                        $("#company-front-submit").attr("disabled",false);
                        error(data.info);
                    }
                }
            });
        });

    });
</script>
